package ewms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import ewms.common.annotation.DataScope;
import ewms.common.core.page.TableDataInfo;
import ewms.common.utils.PageUtils;
import ewms.domain.EwmsWasteDetail;
import ewms.mapper.*;
import ewms.service.IEwmsWasteDetailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

/**
 * 危废 业务层处理
 *
 * @author ruoyi
 */
@Slf4j
@Service
public class EwmsWasteDetailServiceImpl extends ServiceImpl<EwmsWasteDetailMapper, EwmsWasteDetail> implements IEwmsWasteDetailService {

	@Override
	@DataScope(deptAlias = "d", userAlias = "u", isUser = true)
	public TableDataInfo<EwmsWasteDetail> selectPageWasteDetailList(EwmsWasteDetail wasteDetail) {
		return PageUtils.buildDataInfo(baseMapper.selectPageWasteDetailList(PageUtils.buildPage(), wasteDetail));
	}

	/**
	 * 根据条件分页查询危废列表
	 *
	 * @param wasteDetail 危废信息
	 * @return 危废信息集合信息
	 */
	@Override
	@DataScope(deptAlias = "d", userAlias = "u", isUser = true)
	public List<EwmsWasteDetail> selectWasteDetailList(EwmsWasteDetail wasteDetail) {
		return baseMapper.selectWasteDetailList(wasteDetail);
	}

	/**
	 * 通过危废ID查询危废
	 *
	 * @param wasteId 危废ID
	 * @return 危废对象信息
	 */
	@Override
	public EwmsWasteDetail selectWasteById(Long wasteId) {
		return baseMapper.selectWasteDetailById(wasteId);
	}

	/**
	 * 新增保存危废信息
	 *
	 * @param wasteDetail 危废信息
	 * @return 结果
	 */
	@Override
	@Transactional
	public int insertWasteInfo(EwmsWasteDetail wasteDetail) {
		// 新增危废信息
		int rows = baseMapper.insert(wasteDetail);
		return rows;
	}

	/**
	 * 修改保存危废信息
	 *
	 * @param wasteDetail 危废信息
	 * @return 结果
	 */
	@Override
	@Transactional
	public int updateWasteInfo(EwmsWasteDetail wasteDetail) {
		Long wasteId = wasteDetail.getWasteId();
		return baseMapper.updateById(wasteDetail);
	}

	/**
	 * 批量删除危废信息
	 *
	 * @param wasteIds 需要删除的危废ID
	 * @return 结果
	 */
	@Override
	@Transactional
	public int deleteWasteByIds(Long[] wasteIds) {
		List<Long> ids = Arrays.asList(wasteIds);
		return baseMapper.deleteBatchIds(ids);
	}
}
